package com.kitty.game.rank.message;

import com.kitty.game.enter.FiedValue;
import com.kitty.game.rank.model.PersonInfo;
import com.kitty.mina.Modules;
import com.kitty.mina.annotation.ListField;
import com.kitty.mina.annotation.MessageMeta;
import com.kitty.mina.message.Message;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@MessageMeta(module = Modules.MSG_CROSS_RANK_VIEW)
public class RespCrossRankView extends Message {
    /**排行榜类型*/
    private short type;
    /**等级段类型，没有等级段为 ""，否则如 "120-129"*/
    private String levelLimit;
    private int cookie;
    /**我在这个榜的排名，榜外为 0*/
    private short meRank;
    private short count;

    @ListField(2)
    private List<PersonInfo> list;

    /**计算出自己的排名*/
    public void calMeRank(String meGid) {
        for (int i=0, size = list.size(); i<size; i++) {
            PersonInfo personInfo = list.get(i);
            List<FiedValue> list = personInfo.getList();
            for (FiedValue fiedValue : list) {
                /**305为gid*/
                if (fiedValue.getType() == 305) {
                    /**找到自己的gid，则算出自己的排名*/
                    if (fiedValue.getValue().equals(meGid)) {
                        meRank = (short) (i+1);
                        return ;
                    }
                    break;
                }
            }

        }
    }
}
